package com.doordu.soa.service.web.fieldvalidator;

import com.doordu.soa.service.web.annotation.DataValid;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * Created by zjp on 2017/4/19.
 */
public class IntegerValidatorHandler implements BaseValidatorHandler<Integer> {
    @Override
    public String doValidate(DataValid dataValid, Object field, Integer value) {
        if (value < dataValid.min() || value > dataValid.max()) {
            return String.format("范围不正确, [%d-%d]", dataValid.min(), dataValid.max());
        }
        return PASS;
    }

    public String doValidate(DataValid dataValid, Object field, List<Integer> value) {
        String errMsg = null;
        for (Integer fieldValue : value) {
            errMsg = doValidate(dataValid, field, fieldValue);
            if (StringUtils.isNotEmpty(errMsg)) {
                return errMsg;
            }
        }
        return PASS;
    }


}
